package com.wallet.admin.config;


import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;


@Configuration
public class WebMvcConfig  extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/403").setViewName("403");
        registry.addViewController("/system/sysUser/listSysUser").setViewName("system/sys_user_list");
        registry.addViewController("/system/sysUser/toAdd").setViewName("system/sys_user_add");
        registry.addViewController("/system/menu/listMenu").setViewName("system/menu_list");
        registry.addViewController("/system/menu/toAdd").setViewName("system/menu_add");
        registry.addViewController("/system/role/listRole").setViewName("system/role_list");
        registry.addViewController("/system/role/toAdd").setViewName("system/role_add");
        super.addViewControllers(registry);
    }

    //上传文件配置
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 设置文件大小限制 ,超出设置页面会抛出异常信息，
        // 这样在文件上传的地方就需要进行异常信息的处理了;
        factory.setMaxFileSize("160528KB"); // KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("160528KB");
        return factory.createMultipartConfig();
    }
}
